package com.rpoonolly.simplegame.editor;

import com.rpoonolly.simplegame.Config;
import com.rpoonolly.simplegame.core.aabb.AABBEntity;
import com.rpoonolly.simplegame.core.aabb.EntityGameMap;
import com.rpoonolly.simplegame.renderer.SwingEntityRenderer;
import com.rpoonolly.simplegame.textures.TextureLoader;

public class SwingEntityEditRenderer extends SwingEntityRenderer {
	private AABBEntity cursor = new AABBEntity(0, 0, 5, 5);
	
	public SwingEntityEditRenderer(EntityGameMap<AABBEntity> gameWorld, TextureLoader textureLoader) {
		super(gameWorld, textureLoader);
	}
	
	@Override
	public void render() {
		super.render();
		
		if (Config.isEditModeEnabled.get())
			renderFocalPoint();
	}
	
	@Override
	protected void entityRenderWrapper(AABBEntity entity, int x, int y,
			int width, int height) {

		if (Config.isEditModeEnabled.get())
			renderSimpleEntity(entity, x, y, width, height);
		
		super.entityRenderWrapper(entity, x, y, width, height);
	}
	
	private void renderSimpleEntity(AABBEntity entity, int x, int y, int width, int height) {
		if(entity == cursor)
			graphics.setColor(Config.CURSOR_COLOR_DEFAULT);
		else
			graphics.setColor(Config.ENT_COLOR_DEFAULT);
		
		graphics.fillRect(x, y, width, height);
	}
	
	private void renderFocalPoint() {
		cursor.setX((int) focalPoint.x);
		cursor.setY((int) focalPoint.y);
		
		super.render(cursor);
	}
}
